package com.flyee.controller.timer{
	
	import com.flyee.controller.CharacterCartoonController;
	import com.flyee.controller.tools.cartoon.model.AppearanceConfig;
	import com.flyee.model.Charactor;
	import com.flyee.service.pool.ObjectCollection;
	import com.flyee.viewer.CharactorViewer;
	import com.flyee.viewer.SkillViewer;
	
	import flash.events.TimerEvent;
	import flash.utils.Timer;

	public class FightTimer extends Timer{
		
		public var target : Charactor;
		
		public var targetV : CharactorViewer;
		
		public var player : Charactor;
		
		public var playerV : CharactorViewer;
		
		public var skillV : SkillViewer;
		
		public var label : String;
		
		private var frame : int = 0;
		
		public var damage : int;
		
		public var actionTime : int = 480;
		
		public var callbackFn : Function;
		
		public function FightTimer(delay:Number, repeatCount:int=0){
			super(delay, repeatCount);
			this.addEventListener(TimerEvent.TIMER, timerHandler);
		}
		
		public function timerHandler(event : TimerEvent) : void {
			if(this.currentCount * this.delay > actionTime) {
				finish();
				return ;
			}
			frame++;
		}
		
		public function finish() : void {
			this.stop();
			this.removeEventListener(TimerEvent.TIMER, timerHandler);
			callbackFn(ObjectCollection.getCharacterByVid(playerV.vid), target, damage);
			if(playerV.specialContainer.contains(skillV))
				playerV.specialContainer.removeChild(skillV);
			skillV.visible = false;
			player.skillStatus = false;
//			var cartoonController : CharacterCartoonController = ObjectCollection.beansContext.getObject("characterCartoonController") as CharacterCartoonController;
//			cartoonController.changeActionDirect(playerV, AppearanceConfig.MOVE_BY_READY);
			if(skillV.contains(skillV.cartoon))
				skillV.removeChild(skillV.cartoon);
			skillV.cartoon = null;
			skillV = null;
			target = null;
			targetV = null;
			playerV = null;
		}
		
	}
}